<?php

namespace app\admin\controller\mall\order;

use app\admin\controller\mall\Base;

/**
 * 订单投诉
 *
 * @icon fa fa-circle-o
 */
class Complain extends Base
{
    
    /**
     * Complains模型对象
     * @var \app\common\model\mall\order\Complains
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\common\model\mall\order\Complain;
        $this->view->assign("complaintypeList", $this->model->getComplaintypeList());
        $this->view->assign("complainstatusList", $this->model->getComplainstatusList());

    }

    /**
     * 编辑
     */
    public function edit($ids = NULL)
    {
        $row = $this->model->getComplainDetail(0);
        if (!$row) $this->error(__('No Results were found'));
        if ($this->request->isPost())
        {
            $params = $this->request->post("row/a");
            if ($params)
            {
                try
                {
                    $params['complainStatus'] = 4;
                    $params['finalResultTime'] = date('Y-m-d H:i:s');
                    $params['finalHandleStaffId'] = $this->auth->id;

                    //是否采用模型验证
                    if ($this->modelValidate)
                    {
                        $name = basename(str_replace("\\model\\", "\\validate\\", get_class($this->model)));
                        $validate = $this->modelSceneValidate ? $name . '.edit' : $name;
                        $result = $this->validate($params,$validate);
                        if(true !== $result){
                            // 验证失败 输出错误信息
                            $this->error($result);
                        }
                    }
                    $result = $row->allowField(true)->isUpdate(true)->save($params);
                    if ($result !== false)
                    {
                        $this->success();
                    }
                    else
                    {
                        $this->error($row->getError());
                    }
                }
                catch (\think\exception\PDOException $e)
                {
                    $this->error($e->getMessage());
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        $this->assign("row",$row);
        return $this->view->fetch();
    }

    /**
     * 详情
     */
    public function detail($ids = NULL)
    {
        $row = $this->model->getComplainDetail(0);
        if (!$row) $this->error(__('No Results were found'));
        //获取关联的定单
        $this->assign("row",$row);
        return $this->view->fetch();
    }

}
